package net.lgpage.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Window;
import android.view.WindowManager;

import com.matriq.cloudmanager.R;

public abstract class BaseDialog extends Dialog{

	Activity activity;
	
	public BaseDialog(Context context) {
		super(context, R.style.dialog);
		if(context instanceof Activity){
			this.activity = (Activity) context;
		}
	}
	
	protected DialogListener listener;

	public DialogListener getListener() {
		return listener;
	}

	public void setListener(DialogListener listener) {
		this.listener = listener;
	}

	public void onExecute(Object ...objs) {
		dismiss();
		if (listener != null) {
			listener.onDialogExecute(objs);
		}
	}
	
	public Activity getActivity() {
		return activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	public void matchParentWidth(){
		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = getActivity().getWindowManager().getDefaultDisplay().getWidth();
		dialogWindow.setAttributes(lp);
	}
	public void matchParentHeight(){
		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.height = getActivity().getWindowManager().getDefaultDisplay().getHeight();
		dialogWindow.setAttributes(lp);
	}
	public void setGravity(int gravity){
		Window dialogWindow = getWindow();
		dialogWindow.setGravity(gravity);
	}
	
}
